package com.yiyi.credit.manage.sso.service.inner;

import com.yiyi.credit.manage.sso.common.Constant;
import com.yiyi.credit.manage.sso.common.page.PageUtils;
import com.yiyi.credit.manage.sso.common.page.Pagination;
import com.yiyi.credit.manage.sso.mapper.ShopMapper;
import com.yiyi.credit.manage.sso.model.entity.Shop;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ShopService {

    @Autowired
    ShopMapper shopMapper;

    public Pagination getShopPageList(String name, Pagination pagination) {
        Shop shop = new Shop();
        if (StringUtils.isNotBlank(name)) {
            shop.setSname(name);
        }
        long count = shopMapper.getCount(shop.getSname());
        pagination.setRecordsTotal(count);
        pagination.setPage(PageUtils.getPage(count, pagination.getLength()));

        if (count > Constant.LONG_ZERO) {
            pagination.setData(shopMapper.getPageData(name, pagination));
        }
        return pagination;
    }

    public void add(Shop shop) {
        shopMapper.add(shop);
    }

    public void updateShop(Shop shop) {
        shopMapper.updateShop(shop);
    }

    public Shop getShopById(long sid) {
        return shopMapper.getShopById(sid);
    }

    public void deleteShop(Shop shop) {
        shopMapper.deleteShop(shop);
    }

    public List<Map<Integer,String>> getAllShop() {
        return shopMapper.getAllShop();
    }
}
